<template>
	<view class="page_main" :style="{'--color':vuex_config.themeColor1}">
		<view class="main_title">孩子自评：</view>
		<view class="input_view">
			<input v-model="boyNum" class="input" type="number" placeholder="请填写分数" />
			<view :class="['tip',boyNum > 100?'sow_tip':'']">得分不能大于100</view>
		</view>
		<view class="main_title">老师评分:</view>
		<view class="input_view">
			<input v-model="teacherNum" class="input" type="number" placeholder="请填写分数" />
			<view :class="['tip',teacherNum > 100?'sow_tip':'']">得分不能大于100</view>
		</view>
		<view class="main_title">家长评分:</view>
		<view class="list_item" v-for="(item,index) in options" :key="index">
			<view class="title">{{index + 1}}、{{item.name}} （总分{{item.fraction}}分）</view>
			<view class="cont">{{item.content}}</view>
			<view class="input_view">
				<input v-model="item.val" class="input" type="number" placeholder="请填写分数" />
				<view :class="['tip',item.val > item.fraction?'sow_tip':'']">得分不能大于总分</view>
			</view>
		</view>
		<view class="fix_bot_main">
			<view class="fixed_bottom_btn">
				<view class="word" @click="sure">保存评分</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				teacherNum: '',
				boyNum: '',
				infoId: null, // 活动id
				enroll_users_id: null, // 报名 id
				options: []
			}
		},
		components: {},
		onLoad(options) {
			if (options && options.infoId) {
				this.infoId = Number(options.infoId)
				this.enroll_users_id = Number(options.enroll_users_id || 0)
			}
			this.init()
		},
		onReachBottom: function() {},
		methods: {
			init() {
				this.$GetQueryDataList('b_enroll_grade', 1, 100, {
					fk_enroll_info_id: this.infoId
				}).then(({
					data
				}) => {
					this.options = data.map((item) => {
						return {
							val: '',
							...item
						}
					})
				})
			},
			sure() {
				if (!this.boyNum) {
					this.$toast('请填写孩子自评分数')
					return
				} else if (!this.teacherNum) {
					this.$toast('请填写老师评分')
					return
				}
				let bol = this.options.some((item) => {
					return item.val > item.fraction
				})
				if (bol) {
					this.$toast('请正确填写分数，不能超过当前项的总分')
				} else {
					this.$loading()
					let parent = 0
					let arr = this.options.map((item) => {
						parent += Number(item.val || 0)
						return {
							name: item.name,
							content: item.content,
							val: item.val,
							fraction: item.fraction
						}
					})
					let params = {
						scoring_content: JSON.stringify(arr),
						parent: parent
					}
					
					this.$AddNewData('b_enroll_score', {
						fk_enroll_users_id: this.enroll_users_id,
						self_evaluation:this.boyNum,
						teacher:this.teacherNum,
						...params
					}, {
						isWeb: true
					}).then(() => {
						this.successSub()
					})
				}
			},
			successSub() {
				uni.showToast({
					title: '评分成功',
					icon: 'none',
					complete: () => {
						setTimeout(() => {
							this.uniBack()
						}, 1000);
					}
				})
			}
		}
	}
</script>
<style lang="scss" scoped>
	.page_main {
		padding: 0 20rpx;
	}

	.main_title {
		font-weight: bold;
		font-size: 34rpx;
		padding: 20rpx 0;
	}

	.input_view {
		border: 1px solid #dde5ed;
		border-radius: 6rpx;
		position: relative;

		.input {
			padding: 0 20rpx;
			line-height: 68rpx;
			height: 68rpx;
		}

		.tip {
			position: absolute;
			bottom: -40rpx;
			right: 16rpx;
			color: var(--color);
			font-size: 24rpx;
			display: none;

			&.sow_tip {
				display: block;
			}
		}
	}

	.list_item {
		padding: 10rpx 0 40rpx;

		.title {
			font-weight: bold;
			font-size: 30rpx;
		}

		.cont {
			padding: 20rpx 0;
			white-space: pre;
		}


	}
</style>
